//
//  SCHotelInfoController.m
//  shangcheng
//
//  Created by Jie Jie on 2019/7/11.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCHotelInfoController.h"
#import "SDCycleScrollView.h"
#import "SCHotelInfoCell.h"
#import "SCHotelRoomInfoController.h"

#define k_table_rl_space_h       10
#define k_table_tb_space_h       5
#define k_cycle_scrollView_h     kScreenW*188/375
#define k_hotel_info_view_h      kScreenW*80/375
#define k_table_header_view_h    k_cycle_scrollView_h + k_hotel_info_view_h + k_table_tb_space_h
#define k_hotel_room_header_h    kScreenW*82/375
#define k_table_header_h         kScreenW*35/375
#define k_table_footer_h         k_table_header_h + k_table_tb_space_h

#define k_date_view_h            k_hotel_room_header_h * 0.5
#define k_date_label_w           70
#define k_date_timer_label_w     50
#define k_date_button_w          kScreenW - 70 - 50
#define k_date_button_h          30

@interface SCHotelInfoController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate>

@property (nonatomic , strong) UITableView *table_view;
@property (nonatomic , strong) SDCycleScrollView  *cycle_scrollView;// 轮播图

@property (nonatomic , strong) UIButton *date_button;
@property (nonatomic , strong) UILabel *date_label;
@property (nonatomic , strong) NSString *date_text;
@property (nonatomic , strong) UILabel *timer_label;
@property (nonatomic , strong) NSString *timer_text;

@end

@implementation SCHotelInfoController

- (void)viewDidLoad {
    
    [super viewDidLoad];

    self.date_text = [NSString string];
    self.date_text = @"2019/08/08 —— 2019/08/09";
    self.timer_text = [NSString string];
    self.timer_text = @"一晚";
   
    [self.view addSubview:self.table_view];
}

#pragma mark 私有方法 -- UI
-(UIView *)tabelHeaderViewInTopSection{
    
    UIView *header_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, k_table_header_view_h)];
    [header_view addSubview:self.cycle_scrollView];
    
    UIButton *back_button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    [back_button addTarget:self action:@selector(clickBackButton:) forControlEvents:UIControlEventTouchUpInside];
    [header_view addSubview:back_button];
    
    UIImageView *back_image = [[UIImageView alloc] initWithFrame:CGRectMake(7, 9, 10, 17)];
    back_image.image = [UIImage imageNamed:@"back"];
    [back_button addSubview:back_image];
    
    CGFloat share_button_w = 20;
    CGFloat share_button_x = kScreenW - share_button_w - 10;
    UIButton *share_button = [[UIButton alloc] initWithFrame:CGRectMake(share_button_x, 12, share_button_w, 18)];
    [share_button setBackgroundImage:[UIImage imageNamed:@"icon_Collection_n"] forState:UIControlStateNormal];
    [share_button setBackgroundImage:[UIImage imageNamed:@"icon_Collection_s"] forState:UIControlStateSelected];
    [share_button addTarget:self action:@selector(clickShareButton:) forControlEvents:UIControlEventTouchUpInside];
    [header_view addSubview:share_button];
    
    UIView *hotel_info_view = [[UIView alloc] initWithFrame:CGRectMake(0, k_cycle_scrollView_h, kScreenW, k_hotel_info_view_h)];
    hotel_info_view.backgroundColor = [UIColor whiteColor];
    
    UILabel *hotel_name_label = [[UILabel alloc] init];
    hotel_name_label.text = @"泉州友德大酒店";
    hotel_name_label.font = [UIFont systemFontOfSize:16.0f];
    hotel_name_label.textColor = RGB(51, 51, 51);
    hotel_name_label.textAlignment = NSTextAlignmentLeft;
    [hotel_info_view addSubview:hotel_name_label];
    
    UIImageView *hotel_address_img = [[UIImageView alloc] init];
    hotel_address_img.image = [UIImage imageNamed:@"nav_icon_adress"];
    [hotel_info_view addSubview:hotel_address_img];
    
    UILabel *hotel_address_label = [[UILabel alloc] init];
    hotel_address_label.text = @"泉州万达广场 刺桐北路与田淮街交界处泉州轻艺大厦1楼";
    hotel_address_label.font = [UIFont systemFontOfSize:11.0f];
    hotel_address_label.textColor = RGB(102, 102, 102);
    hotel_address_label.textAlignment = NSTextAlignmentLeft;
    hotel_address_label.numberOfLines = 2;
    [hotel_info_view addSubview:hotel_address_label];
    
    UIView *line_view = [[UIView alloc] init];
    line_view.backgroundColor = RGB(230, 230, 230);
    [hotel_info_view addSubview:line_view];
    
    UIButton *hotel_tel_button = [[UIButton alloc] init];
    [hotel_tel_button setBackgroundImage:[UIImage imageNamed:@"phone"] forState:UIControlStateNormal];
    [hotel_tel_button addTarget:self action:@selector(clickTelButton:) forControlEvents:UIControlEventTouchUpInside];
    [hotel_info_view addSubview:hotel_tel_button];
    [header_view addSubview:hotel_info_view];
   
    CGFloat address_img_h = 15;
    CGFloat tel_button_h = 30;
    CGFloat hotel_info_view_space = 25;
    CGFloat hotel_info_label_h = (k_hotel_info_view_h - k_table_tb_space_h * 2) * 0.5;

    [hotel_name_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(k_table_tb_space_h);
        make.left.mas_equalTo(k_table_rl_space_h);
        make.right.mas_equalTo(-k_table_rl_space_h);
        make.height.mas_equalTo(hotel_info_label_h);
        
    }];

    [hotel_address_img mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.mas_equalTo(hotel_name_label.mas_bottom).mas_offset((hotel_info_label_h - address_img_h)* 0.5);
        make.left.mas_equalTo(k_table_rl_space_h + 3);
        make.width.mas_equalTo(13);
        make.height.mas_equalTo(address_img_h);
    }];
    [hotel_address_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(hotel_name_label.mas_bottom);
    make.left.mas_equalTo(hotel_address_img.mas_right).mas_offset(5);
        make.height.mas_equalTo(hotel_info_label_h);
    }];
    [line_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(hotel_name_label.mas_bottom);
    make.left.mas_equalTo(hotel_address_label.mas_right).mas_offset(hotel_info_view_space * 2);
        make.height.mas_equalTo(tel_button_h);
        make.width.mas_equalTo(1);
    }];
    [hotel_tel_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(hotel_name_label.mas_bottom);
    make.left.mas_equalTo(line_view.mas_right).mas_offset(hotel_info_view_space);
        make.height.and.width.mas_equalTo(tel_button_h);
        make.right.mas_equalTo(-hotel_info_view_space);
    }];
   
    return header_view;
    
}

-(UIView *)tabelHeaderViewByOneSection{
    
    UIView *header_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, k_hotel_room_header_h)];
    header_view.backgroundColor = [UIColor whiteColor];
    
    UIView *date_view = [[UIView alloc] init];
    date_view.backgroundColor = [UIColor whiteColor];
    [header_view addSubview:date_view];
    //筛选
    UIView *screen_view = [[UIView alloc] init];
    screen_view.backgroundColor = [UIColor whiteColor];
    [header_view addSubview:screen_view];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @"选择日期";
    label.font = [UIFont systemFontOfSize:13.0f];
    label.textAlignment = NSTextAlignmentCenter;
    [date_view addSubview:label];
    
    UIImageView *date_img = [[UIImageView alloc] init];
    date_img.image = [UIImage imageNamed:@"rl"];
    [self.date_button addSubview:self.date_label];
    [self.date_button addSubview:date_img];
    
    [date_view addSubview:self.date_button];
    [date_view addSubview:self.timer_label];
    
    [date_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(1);
        make.left.and.right.mas_equalTo(0);
        make.height.mas_equalTo(k_date_view_h);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.and.bottom.mas_equalTo(0);
        make.width.mas_equalTo(k_date_label_w);
    }];
    
    [self.date_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label.mas_right);
        make.top.mas_equalTo((k_date_view_h - k_date_button_h) * 0.5);
        make.width.mas_equalTo(k_date_button_w);
        make.height.mas_equalTo(k_date_button_h);
        
    }];
    
    [self.date_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(8);
        make.top.and.bottom.mas_equalTo(0);
        make.right.mas_equalTo(date_img.mas_left);
    }];
    
    [date_img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo((k_date_button_h - 13) * 0.5);
        make.width.mas_equalTo(13);
        make.height.mas_equalTo(13);
        make.right.mas_equalTo(-10);
    }];
    
    [self.timer_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.date_button.mas_right);
        make.right.and.top.and.bottom.mas_equalTo(0);
        make.width.mas_equalTo(k_date_timer_label_w);
    }];
    
    UIView *hotel_shop_type_view = [[UIView alloc] init];
    [header_view addSubview:hotel_shop_type_view];
    
    CGFloat hotel_shop_type_space = 10;
    CGFloat hotel_shop_type_button_w = 60;
    CGFloat hotel_shop_type_button_h = 20;
    CGFloat hotel_shop_type_button_y = k_date_view_h +(k_date_view_h - hotel_shop_type_button_h) * 0.5 ;
    
    NSMutableArray *hotel_shop_type_array = [NSMutableArray arrayWithObjects:@"全部",@"双人床",@"小床", nil];
    for (int i = 0; i < hotel_shop_type_array.count; i++) {
       
        NSString *titel_text = [NSString stringWithFormat:@"%@",hotel_shop_type_array[i]];
        
        UIButton *hotel_shop_type_button = [[UIButton alloc] initWithFrame:CGRectMake(hotel_shop_type_space + (hotel_shop_type_button_w + hotel_shop_type_space) * i, hotel_shop_type_button_y, hotel_shop_type_button_w, hotel_shop_type_button_h)];
        [hotel_shop_type_button setBackgroundColor:RGB(231, 157, 58)];
        [hotel_shop_type_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        hotel_shop_type_button.titleLabel.font = [UIFont systemFontOfSize:12.0f];
        hotel_shop_type_button.layer.masksToBounds = YES;
        hotel_shop_type_button.layer.cornerRadius = 3;
        [hotel_shop_type_button setTitle:titel_text forState:UIControlStateNormal];
        [hotel_shop_type_view addSubview:hotel_shop_type_button];
        
    }
    
    UIView *bottom_line_view = [[UIView alloc] init];
    bottom_line_view.backgroundColor = RGB(230, 230, 230);
    [header_view addSubview:bottom_line_view];
    [bottom_line_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.and.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    return header_view;
    
}

#pragma mark 私有方法 -- 初始化
-(UITableView *)table_view{
    
    if (_table_view == nil) {
        _table_view = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
        _table_view.delegate = self;
        _table_view.dataSource = self;
        _table_view.backgroundColor = RGB(244, 244, 244);
        [_table_view setTableHeaderView:[self tabelHeaderViewInTopSection]];
        
    }
    return _table_view;
}

-(SDCycleScrollView *)cycle_scrollView{
    
    if (_cycle_scrollView == nil) {
        
        _cycle_scrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenW, k_cycle_scrollView_h) delegate:self placeholderImage:[UIImage imageWithColor:BGColor]];
        _cycle_scrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _cycle_scrollView.currentPageDotColor = RGB(251, 30, 72);
        _cycle_scrollView.pageDotColor = [UIColor whiteColor];
        _cycle_scrollView.autoScrollTimeInterval = 3.0f;
        _cycle_scrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    }
    return _cycle_scrollView;
    
}

-(UIButton *)date_button{
    
    if (_date_button == nil) {
        _date_button = [[UIButton alloc] init];
        [_date_button setBackgroundColor:RGB(244, 244, 244)];
        [_date_button addTarget:self action:@selector(clickDateButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _date_button;
    
}

-(UILabel *)date_label{
    
    if (_date_label == nil) {
        _date_label = [[UILabel alloc] init];
        _date_label.text = self.date_text;
        _date_label.textColor = RGB(51, 51, 51);
        _date_label.font = [UIFont systemFontOfSize:13.0f];
    }
    return _date_label;
}

-(UILabel *)timer_label{
    
    if (_timer_label == nil) {
        _timer_label = [[UILabel alloc] init];
        _timer_label.text = self.timer_text;
        _timer_label.textColor = RGB(219, 52, 52);
        _timer_label.font = [UIFont systemFontOfSize:13.0f];
        _timer_label.textAlignment = NSTextAlignmentCenter;
    }
    return _timer_label;
}

#pragma mark 私有方法 -- 点击事件
-(void)clickTelButton:(UIButton *)sender{
    
}

-(void)clickDateButton:(UIButton *)sender{
    
}

-(void)clickBackButton:(UIButton *)sender{

    [self.navigationController popViewControllerAnimated:YES];
}

-(void)clickShareButton:(UIButton *)sender{
    
}

#pragma mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0 || section == 1 ) {
        return 3;
    }else if ( section == 2 || section == 3 || section == 4){
        return 1;
    }
    
    return 0;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifity1;
    
    if (indexPath.section == 0) {
        
        identifity1 = @"SCHotelRoomViewCell";
        SCHotelInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:identifity1];
        if (cell == nil) {
            cell = [[SCHotelInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifity1 ];
        }
        
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
        
        return cell;
    }else if (indexPath.section == 1) {
        
        identifity1 = @"SCHotelEvaluateViewCell";
        SCHotelInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:identifity1];
        if (cell == nil) {
            cell = [[SCHotelInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifity1 ];
        }
        
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
        
        return cell;
    }else if (indexPath.section == 2) {
        
        identifity1 = @"SCHotelSetViewCell";
        SCHotelInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:identifity1];
        if (cell == nil) {
            cell = [[SCHotelInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifity1 ];
        }
        
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
        
        return cell;
    }else if (indexPath.section == 3) {
        
        identifity1 = @"SCHotelNoticeViewCell";
        SCHotelInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:identifity1];
        if (cell == nil) {
            cell = [[SCHotelInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifity1 ];
        }
        
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
        
        return cell;
    }else if (indexPath.section == 4) {
        
        identifity1 = @"SCHotelNoticeImageViewCell";
        SCHotelInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:identifity1];
        if (cell == nil) {
            cell = [[SCHotelInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifity1 ];
        }
        
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
        
        return cell;
    }
    
    identifity1 = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifity1];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifity1 ];
    }
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        
        return k_hotel_room_cell_h;
        
    }else if (indexPath.section == 1){
        
        return k_hotel_evaluate_cell_h;
        
    }else if (indexPath.section == 2) {
        
        return k_hotel_set_cell_h;
        
    }else if (indexPath.section == 3) {
        
        return k_hotel_notice_cell_h;
        
    }else if (indexPath.section == 4) {
        
        return k_hotel_notice_img_cell_h;
        
    }
    
    return 87;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
      return k_hotel_room_header_h;
    }else if (section == 1 || section == 2 || section == 3 || section == 4){
      return k_table_header_h;
    }
    
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    if (section == 0 || section == 1) {
        return k_table_footer_h;
    }else if (section == 2 || section == 3 || section == 4){
        return k_table_tb_space_h;
    }
    
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        
        UIView *headerV = [self tabelHeaderViewByOneSection];
        return headerV;
        
    }else if (section == 1 || section == 2 || section == 3 || section == 4){
       
        UIView *headerV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, k_table_header_h)];
        headerV.backgroundColor =  [UIColor whiteColor];
       
        UILabel *title_label = [[UILabel alloc] init];
        title_label.textColor = RGB(51, 51, 51);
        title_label.font = [UIFont systemFontOfSize:13.0f];
        title_label.textAlignment = NSTextAlignmentLeft;
        [headerV addSubview:title_label];

        [title_label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(8);
            make.bottom.mas_equalTo(0);
            make.top.mas_equalTo(0);
            make.right.mas_equalTo(0);
        }];
        
        if (section == 1){
            title_label.text = @"用户评价";
        }else if (section == 2) {
            title_label.text = @"酒店设置";
        }else if (section == 3) {
            title_label.text = @"入住须知";
        }else if (section == 4) {
            title_label.text = @"入住须知";
        }
        
        return headerV;
    }
    
   
    return nil;
    
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *footerV = [[UIView alloc] init];
    
    if (section == 0) {
       
        footerV.frame = CGRectMake(0, 0, kScreenW, k_table_footer_h);
        footerV.backgroundColor =  RGB(206, 206, 206);
        
        UIButton *more_button = [[UIButton alloc] init];
        [more_button setTitle:@"展开全部-->" forState:UIControlStateNormal];
        [more_button setBackgroundColor:[UIColor whiteColor]];
        [more_button setTitleColor:RGB(142, 142, 142) forState:UIControlStateNormal];
        more_button.titleLabel.font = [UIFont systemFontOfSize:11];
        [footerV addSubview:more_button];
        
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = RGB(206, 206, 206);
        [footerV addSubview:view];
        
        [more_button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(1);
            make.left.and.right.mas_equalTo(0);
            make.height.mas_equalTo(k_table_header_h);
        }];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.mas_equalTo(0);
            make.height.mas_equalTo(k_table_tb_space_h);
            make.top.mas_equalTo(more_button.mas_bottom);
        }];
  
    }else if (section == 1){
        
        footerV.frame = CGRectMake(0, 0, kScreenW, k_table_footer_h);
        footerV.backgroundColor =  RGB(206, 206, 206);
        
        UIButton *more_button = [[UIButton alloc] init];
        [more_button setTitle:@"展开全部-->" forState:UIControlStateNormal];
        [more_button setBackgroundColor:[UIColor whiteColor]];
        [more_button setTitleColor:RGB(142, 142, 142) forState:UIControlStateNormal];
        more_button.titleLabel.font = [UIFont systemFontOfSize:11];
        [footerV addSubview:more_button];
        
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = RGB(206, 206, 206);
        [footerV addSubview:view];
        
        [more_button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(1);
            make.left.and.right.mas_equalTo(0);
            make.height.mas_equalTo(k_table_header_h);
        }];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.mas_equalTo(0);
            make.height.mas_equalTo(k_table_tb_space_h);
            make.top.mas_equalTo(more_button.mas_bottom);
        }];
        
    }else if (section == 2 || section == 3 || section == 4){
        
        footerV.frame = CGRectMake(0, 0, kScreenW, k_table_tb_space_h);
        footerV.backgroundColor = RGB(206, 206, 206);
        
    }
    
    
     return footerV;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SCHotelRoomInfoController *vc = [[SCHotelRoomInfoController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
